package com.um.jdy.platform.platform.manager;


import cn.hutool.core.bean.BeanUtil;
import com.um.jdy.common.platform.entity.dto.AppSettingDTO;
import com.um.jdy.common.platform.entity.po.AppSetting;
import com.um.jdy.common.platform.entity.vo.AppSettingVO;
import com.um.jdy.common.platform.service.AppSettingService;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.manager.BaseManager;
import com.um.springboot.starter.utils.UMBeanUtils;
import org.springframework.stereotype.Component;

/**
 * 管理类：应用信息设置
 */
@Component
public class AppSettingManager extends BaseManager<AppSettingService> {

    /**
     * 详情
     *
     * @return
     */
    public Response<AppSettingVO> get() {
        AppSetting appSetting = service.getEntity("com_id", getComId());
        if(appSetting == null){
            appSetting = new AppSetting();
            appSetting.setComId(getComId());
            appSetting.setCompanyName("XX科技有限公司");
            service.save(appSetting);
        }
        return Response.success(UMBeanUtils.copyBean(appSetting,AppSettingVO.class));
    }

    /**
     * 更新
     *
     * @param id
     * @param appSettingDTO
     * @return
     */
    public Response update(String id, AppSettingDTO appSettingDTO) {
        AppSetting appSetting = BeanUtil.copyProperties(appSettingDTO, AppSetting.class);
        appSetting.setPlatformAppSettingId(id);
        service.updateEntity(appSetting);
        return Response.success();
    }

}
